﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using TdolDemo_QBZ.Models;
using TdolDemo_QBZ.Domain;
using TdolDemo_QBZ.Models.Task;

namespace TdolDemo_QBZ.Controllers
{
    public class HomeController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        public IActionResult GetTask(int taskid = 0)
        {
            var taskList = (new TdolTaskUnitListDomain()).GetTaskUnitList(taskid);

            ViewData["taskList"] = taskList;
            ViewData["Message"] = "这是你所需要的LIST";

            return View();
            //return Json(taskList);
        }

        public IActionResult AddTask(TaskModel task)
        {
            //var taskList = (new TdolTaskListDomain()).GetTaskList(taskid);
            task.CreateOn = DateTime.Now;
            task.Guid = Guid.NewGuid();
            task.IsDelete = 0;
            var newtask = (new TdolTaskListDomain()).AddTaskList(task);
            if (newtask > 0)
            {
                ViewData["Message"] = "ok";

            }
            else
            {
                ViewData["Message"] = "error";
            }
            return View();
            //return Json(newtask);
        }

        public IActionResult DelateTask(int taskid)
        {
            if((new TdolTaskListDomain()).DelateTaskList(taskid) > 0)
            {
                return Json("删除成功");
            }
            else
            {
                return Json("删除失败");
            }
        }

        public IActionResult About()
        {

            ViewData["Message"] = "Your application description page.";

            return View();
        }

        public IActionResult Contact()
        {
            ViewData["Message"] = "Your contact page.";

            return View();
        }

        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
